<template>
    <div class="box">
        <h3>axios 的模块化</h3>
        <pre>{{ types }}</pre>
        <input type="button" value="加载数据" @click="updataTypes()">
        <input type="button" value="加载数据2" @click="updatatypes2()">
        <hr>
        <p>电影项目 -首页数据请求处理</p>
        <pre>{{ result }}</pre>
        <input type="button" value="加载电影" @click="updataFilms()">
    </div>

</template>
<script>
import api from '@/index/api'
export default {
    data() {
        return {
            types: [],
            result:[]
        }
    },
    methods: {
        updataTypes() {
            api.loadTypes()
                .then((res) => {


                    this.types = res.data
                })
        },
        async updatatypes2() {
            let { data } = await api.loadTypes()


            this.types = data

        },
        async updataFilms() {
            let { data } = await api.loadTypes()

            for (let t of data) {
                console.log(t);
                let res = await api.loadFilms({
                    tid: t.typeId,
                    pageSize:1
                })
                console.log(res,'222');
                
                t.list = res.data

            }
            this.result=data


        }
    }
}

</script>